package com.integration.gateway;

import com.integration.gateway.pojo.Order;
import com.integration.gateway.pojo.OrderItem;
import lombok.extern.slf4j.Slf4j;
import org.springframework.integration.annotation.MessageEndpoint;
import org.springframework.integration.annotation.Splitter;

import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@MessageEndpoint
public class OrderSplitter {

    @Splitter(inputChannel = "orders", outputChannel = "drinks")
    public List<OrderItem> orderSplit(Order order){
        log.info("=== order split ===");
        return order.getOrderItems().stream().filter(o -> o.isDrink()).collect(Collectors.toList());
    }
}
